package com.jsj.controller;

import com.jsj.domain.Label;
import com.jsj.domain.Number;
import com.jsj.service.LabelService;
import com.jsj.service.NumberService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/number")
public class NumberController {
    private NumberService numberService;

    @Autowired

    public void setNumberService(NumberService numberService) {
        this.numberService = numberService;
    }

    /**
     * 查询标签
     */
    @RequestMapping(value = "/queryById", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('student,teacher,admin')")
    public Number queryById(@RequestBody int problemId) {
        return numberService.queryById(problemId);
    }

    /**
     * 创建标签
     */
    @RequestMapping(value = "/insert", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public AjaxResult insert(@RequestBody Number number) {
        if (numberService.insert(number) == 0) {
            return AjaxResult.error("创建题号失败");
        }
        return AjaxResult.success("创建题号成功");
    }
}
